// 格式化地址
// 格式化地址
export const formatAddress = (areaList) => {
  const { provinceList, cityList, countyList } = areaList
  // 转换省级数据
  return Object.entries(provinceList).map(([provinceCode, provinceName]) => {
    // 处理当前省对应的市级数据
    const cities = Object.entries(cityList)
    // 筛选属于当前省的市（前2位编码匹配）
      .filter(([cityCode]) => cityCode.startsWith(provinceCode.substring(0, 2)))
      .map(([cityCode, cityName]) => {
        // 处理当前市对应的区级数据
        const counties = Object.entries(countyList)
        // 筛选属于当前市的区（前4位编码匹配）
          .filter(([countyCode]) => countyCode.startsWith(cityCode.substring(0, 4)))
          .map(([countyCode, countyName]) => ({
            value: countyCode,
            label: countyName
          }))

        // 构建市级节点（有区数据才包含children）
        return {
          value: cityCode,
          label: cityName,
          ...(counties.length && { children: counties })
        }
      })

    // 构建省级节点（有市数据才包含children）
    return {
      value: provinceCode,
      label: provinceName,
      ...(cities.length && { children: cities })
    }
  })
}
